#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N=2e5+10;
ll a[N];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n,k,q;
		cin>>n>>k>>q;
		int cnt=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",a+i);
		}
		ll ans=0;
		for(int i=1;i<=n;i++)
		{
			cnt=0;
			int j=i;
			while(a[j]<=q && j<=n)
			{
				j++;
				cnt++;
			}
			if(cnt>=k)
			{
				ll r=cnt-k+1;
				ll l=1;
				ll num=r-l+1;
				ans=ans+(l+r)*num/2;
			}
			i=j;
		}
		cout<<ans<<endl;
	}

	return 0;
}

